<template>
  <el-dialog
  title="题目审核"
  class="question-check"
  :visible="questionCkeckDialogVisibleShow"
  width="30%"
  @close="close">
  <el-form :model="questionCheck">
    <el-form-item>
      <el-radio v-model="questionCheck.chkState" label="1">通过</el-radio>
      <el-radio v-model="questionCheck.chkState" label="2">拒绝</el-radio>
    </el-form-item>
    <el-form-item>
      <el-input
        type="textarea"
        :rows="2"
        placeholder="请输入审核意见"
        v-model="questionCheck.chkRemarks">
      </el-input>
    </el-form-item>
  </el-form>
  <span slot="footer" class="dialog-footer">
    <el-button @click="close">取 消</el-button>
    <el-button type="primary" @click="questionsCheckOnConfirm">确 定</el-button>
  </span>
</el-dialog>
</template>

<script>
import { choiceCheck } from '@/api/hmmm/questions'
export default {
  name: 'QuestionsCheck',
  props: {
    questionCkeckDialogVisibleShow: {
      type: Boolean,
      default: false
    },
    questionCkeckId: {
      type: [Number, String],
      required: true
    }
  },
  data () {
    return {
      questionCheck: {
        chkState: '1',
        chkRemarks: ''
      }
    }
  },
  methods: {
    close () {
      this.$emit('update:questionCkeckDialogVisibleShow', false)
    },
    // 确认检查
    async questionsCheckOnConfirm () {
      if (!this.questionCheck.chkRemarks.trim()) {
        return this.$message.warning('请输入审核意见')
      }
      try {
        this.questionCheck.chkState = this.questionCheck.chkState - 0
        this.questionCheck.id = this.questionCkeckId
        await choiceCheck(this.questionCheck)
        this.$message.success('操作成功')
        this.questionCheck = {
          chkState: '1',
          chkRemarks: ''
        }
        this.close()
        this.$emit('disable-check', true)
        this.$emit('handler-update-check')
      } catch (error) {
        this.$message.error('题目审核失败！')
      }
    }
  }
}
</script>

<style scoped lang='less'>
.question-check {
  /deep/.el-dialog__footer {
    text-align: right;
  }

}
</style>
